//
//  OrderInforMoneyTableViewCell.m
//  GLGW_Shoping
//
//  Created by yang on 2018/12/7.
//  Copyright © 2018年 yang. All rights reserved.
//

#import "OrderInforMoneyTableViewCell.h"

@implementation OrderInforMoneyTableViewCell
{
    NSMutableArray *labArr;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        NSArray * leftTitArr = @[@"商品总计",@"商品金额总计",@"其他金额总计",@"订单金额总计"];
        labArr = [NSMutableArray array];
        for (int i=0; i<4; i++) {
            GLGWLabel * leftLabel = [[GLGWLabel alloc] initWithFont:SYSTEMFONT(14) theColor:kColor_Rule_Black inSuperView:self.contentView];
            leftLabel.text = leftTitArr[i];
            [leftLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(self.contentView.mas_left).offset(kWidthProportion_In_iPhoneTriploid(15));
                make.top.equalTo(self.contentView.mas_top).offset(kHeightProportion_In_iPhoneTriploid(12)+kHeightProportion_In_iPhoneTriploid(32)*i);
                make.height.equalTo(@(kHeightProportion_In_iPhoneTriploid(20)));
            }];
            //
            GLGWLabel * rightLabel;
            if (i < 3) {
                rightLabel = [[GLGWLabel alloc] initWithFont:SYSTEMFONT(14) theColor:[UIColor colorWithHexString:@"#999999"] inSuperView:self.contentView];
                rightLabel.text = @"23.564 吨";
                [rightLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.right.equalTo(self.contentView.mas_right).offset(-kWidthProportion_In_iPhoneTriploid(15));
                    make.top.height.equalTo(leftLabel);
                }];
            } else {
                rightLabel = [[GLGWLabel alloc] initWithFont:SYSTEMFONT(18) theColor:[UIColor colorWithHexString:@"#EC5353"] inSuperView:self.contentView];
                rightLabel.text = @"¥177149.96";
                [rightLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.right.equalTo(self.contentView.mas_right).offset(-kWidthProportion_In_iPhoneTriploid(15));
                    make.top.equalTo(self.contentView.mas_top).offset(kHeightProportion_In_iPhoneTriploid(104));
                    make.height.equalTo(@(kHeightProportion_In_iPhoneTriploid(25)));
                }];
            }
            rightLabel.tag = 125+i;
            [labArr addObject:rightLabel];
        }
    }
    return self;
}

- (void)refreshOrderInforMoneyTableViewCell:(OrderInfomationDetailDataInfoModel *)model index:(NSIndexPath *)index
{
    NSArray *arr = model.orderGoods;
    NSInteger allWi = 0;
    NSDecimalNumber *totalPrice = [NSDecimalNumber decimalNumberWithString:@"0"];
    for (OrderInfomationDetailDataInfoOrderGoodsModel *orderGoodsModel in arr) {
        // 总重量
        NSInteger goosNum = orderGoodsModel.goodsNum;
        NSInteger widhtNu = [orderGoodsModel.weightCounting integerValue];
        NSInteger allGoodsWig = goosNum * widhtNu;
        allWi += allGoodsWig;
        
        // 总钱数
        NSDecimalNumber *pri = [NSDecimalNumber decimalNumberWithString:@"0"];
        if (orderGoodsModel.modifyPrice > 0) {
            pri = orderGoodsModel.modifyPrice;
        } else {
            pri = orderGoodsModel.price;
        }
        NSDecimalNumber *goosNumDecimal = [NSDecimalNumber decimalNumberWithString:[NSString stringWithFormat:@"%ld",(long)goosNum]];
        NSDecimalNumber *everOrderMoney = [pri decimalNumberByMultiplyingBy:goosNumDecimal];
        NSDecimalNumber *jiafa = [totalPrice decimalNumberByAdding:everOrderMoney];
        totalPrice = jiafa;
    }
    
    NSString *toStr = [NSString stringWithFormat:@"¥%@",totalPrice];
    
    for (int i = 0; i < labArr.count; i ++) {
        GLGWLabel *lab = labArr[i];
        if (i == 0) {
            lab.text = [NSString stringWithFormat:@"%ld吨",allWi];
        } else if (i == 1 || i == 3) {
            lab.text = toStr;
        } else {
            lab.text = @"¥0.00";
        }
    }
}


@end
